package com.cat.chapter047;

import java.io.*;
import java.util.Arrays;

/**
 * @author cat
 * @description https://www.luogu.com.cn/problem/P4231
 * @create 2025/7/16 14:00
 * @since JDK17
 */

public class Solution02 {
    static int MAXN = ((int) (1e7 + 10));
    static long[] arr = new long[MAXN];
    static long n, m, l, r, s, e;
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter pr = new PrintWriter(new OutputStreamWriter(System.out));
    static StreamTokenizer tokenizer = new StreamTokenizer(br);

    public static void set(int l, int r, long s, long e, long d) {
        arr[l] += s;
        arr[l + 1] += d - s;
        arr[r + 1] -= d + e;
        arr[r + 2] += e;
    }

    public static void main(String[] args) throws IOException {
        Arrays.fill(arr, 0);
        tokenizer.nextToken();
        n = ((int) tokenizer.nval);
        tokenizer.nextToken();
        m = ((int) tokenizer.nval);
        for (int i = 0; i < m; i++) {
            tokenizer.nextToken();
            l = ((int) tokenizer.nval);
            tokenizer.nextToken();
            r = ((int) tokenizer.nval);
            tokenizer.nextToken();
            s = ((long) tokenizer.nval);
            tokenizer.nextToken();
            e = ((long) tokenizer.nval);
            set(((int) l), ((int) r), s, e, (e - s) / (r - l));
        }
        long ans1 = Integer.MIN_VALUE, ans2 = 0;
        for (int i = 1; i <= n; i++) {
            arr[i] += arr[i - 1];
        }
        for (int i = 1; i <= n; i++) {
            arr[i] += arr[i - 1];
            ans1 = Math.max(ans1, arr[i]);
            ans2 ^= arr[i];
        }
        pr.println(ans2 + " " + ans1);
        br.close();
        pr.flush();
        pr.close();
    }
}
